package main

import "fmt"

/*
给定一个二叉树，返回它的 前序 遍历。
https://leetcode-cn.com/problems/binary-tree-preorder-traversal/
*/

/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

var res []int

func preorderTraversal(root *TreeNode) []int {
	res = []int{}
	dfs(root)
	return res
}

func dfs(root *TreeNode) {
	if root != nil {
		res = append(res, root.Val)
		dfs(root.Left)
		dfs(root.Right)
	}
}



func main() {

	nums := []interface{}{1,nil,2,3}
	fmt.Println(nums)


}
